package com.ddtech.business.practice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddtech.business.check.vo.res.QueTypeRes;
import com.ddtech.business.practice.dto.UserRecordDto;
import com.ddtech.business.practice.dto.WorkbookDto;
import com.ddtech.business.practice.entity.PracticeUserRecord;
import com.ddtech.business.practice.query.PracticeUserRecordQuery;
import com.ddtech.business.practice.service.PracticeService;
import com.ddtech.business.practice.service.PracticeUserRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 练习
 * </p>
 *
 * @author bin_pu
 * @since 2023-05-26
 */
@Api(tags = "业务-题库练习")
@RestController
@RequestMapping("/practice")
public class PracticeController {
    @Autowired
    private PracticeService practiceService;

    @Autowired
    private PracticeUserRecordService practiceUserRecordService;

    @ApiOperation(value = "查询练习记录")
    @GetMapping(value = "/record")
    public ResponseEntity getUserRecord(@RequestParam @ApiParam("页码") int page,
                                        @RequestParam @ApiParam("页面大小") int size,
                                        String startTime,
                                        String endTime) {
        IPage pageableRequest = new Page(page + 1, size);
        return new ResponseEntity(practiceService.getUserRecord(pageableRequest,startTime,endTime), HttpStatus.OK);
    }


    @ApiOperation(value = "练习")
    @PostMapping("/workbook")
    public ResponseEntity<QueTypeRes> workbook(@RequestBody WorkbookDto workbookDto) {
        return new ResponseEntity(practiceService.workbook(workbookDto), HttpStatus.OK);
    }


    @ApiOperation(value = "提交")
    @PostMapping("/commit")
    public ResponseEntity commit(@RequestBody @ApiParam("答题记录实体") UserRecordDto recordDto) {
        PracticeUserRecord practiceUserRecord = practiceService.commit(recordDto);
        return new ResponseEntity(practiceUserRecord, HttpStatus.OK);
    }

    @ApiOperation(value = "查询练习统计")
    @GetMapping(value = "/statistics")
    public ResponseEntity getStatistics() {
        return new ResponseEntity(practiceService.getStatistics(), HttpStatus.OK);
    }


    @ApiOperation(value = "APP题库首页今日练习数据统计")
    @GetMapping(value = "/statistics-app")
    public ResponseEntity getStatisticsApp() {
        return new ResponseEntity(practiceUserRecordService.getStatisticsApp(), HttpStatus.OK);
    }

    @ApiOperation(value = "APP题库近7天练习题目数据")
    @GetMapping(value = "/seven-practice-app")
    public ResponseEntity getSevenPracticeList() {
        return new ResponseEntity(practiceUserRecordService.getSevenPracticeList(), HttpStatus.OK);
    }

    @ApiOperation(value = "PC题库近15天练习题目数据")
    @GetMapping(value = "/half-month-practice")
    public ResponseEntity getHalfMonthPracticeList() {
        return new ResponseEntity(practiceUserRecordService.getHalfMonthPracticeList(), HttpStatus.OK);
    }

    @ApiOperation(value = "根据题库查询专项检测排名")
    @GetMapping(value = "/bank-list")
    public ResponseEntity getPageCourseList(PracticeUserRecordQuery practiceUserRecordQuery) {
        return new ResponseEntity(practiceUserRecordService.pageBankList(practiceUserRecordQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询专项检测平均成绩")
    @GetMapping(value = "/type-check-list")
    public ResponseEntity getTypeCHeckList(PracticeUserRecordQuery practiceUserRecordQuery) {
        return new ResponseEntity(practiceUserRecordService.typeCHeckList(practiceUserRecordQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询综合检测平均成绩")
    @GetMapping(value = "/all-check-list")
    public ResponseEntity getAllCHeckList(PracticeUserRecordQuery practiceUserRecordQuery) {
        return new ResponseEntity(practiceUserRecordService.allCHeckList(practiceUserRecordQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询所有用户成绩")
    @GetMapping(value = "/all-user-grade")
    public ResponseEntity getAllUserGrade(PracticeUserRecordQuery practiceUserRecordQuery) {
        return new ResponseEntity(practiceUserRecordService.allUserGrade(practiceUserRecordQuery), HttpStatus.OK);
    }
}
